<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" th:with="title='sys_job'">
<meta charset="utf-8">
<header th:replace="header::header(${title})"></header>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="col-sm-12">
			<div class="ibox">
				<div class="ibox">
				<div class="fixed-table-toolbar" id="toolbar">
					<a shiro:hasPermission="sys:job:add" class="btn    btn-primary  btn-circle" onclick="add()" title="添加"> <i class="fa fa-plus" aria-hidden="true"></i>
					</a> <a shiro:hasPermission="sys:job:batchRemove" class="btn   btn-danger btn-circle" onclick="batchRemove()" title="批量删除"> <i class="fa fa-trash" aria-hidden="true"></i>
					</a> 
				</div>
				<table id="bootstrap-table" data-mobile-responsive="true">
				</table>
			</div>
			</div>
		</div>
	</div>
	<div th:replace="footer :: footer"></div>
	<script type="text/javascript" th:inline="javascript">
	var prefix = ctx + "sys/job";
	var s_edit_h = [[${@permission.hasPermi('sys:job:edit')}]];
	var s_remove_h = [[${@permission.hasPermi('sys:job:remove')}]];
	$().ready(function() {
		load();
	});
	
	function load() {
		var options = {
		    url : prefix + "/list",
		    columns : [ {
	            checkbox : true
            },
            {
                field : 'jobName',
                title : '任务名称'
            },
            {
                field : 'jobGroup',
                title : '任务组名'
            },
            {
                field : 'jobClassName',
                title : '任务方法'
            },
            {
                field : 'description',
                title : '任务描述'
            },
            {
                field : 'cronExpression',
                title : 'cron执行表达式'
            },
            {
                field : 'status',
                title : '任务状态',
                align : 'center',
                formatter : function(value, row, index) {
	                if (value == '0') {
		                return '<a class="fa fa-toggle-off text-info fa-2x" title="启动任务" onclick="resume(\'' + row.jobId + '\')"></a>';
	                } else if (value == '1') {
		                return '<a class="fa fa-toggle-on text-info fa-2x" title="暂停任务" onclick="pause(\'' + row.jobId + '\')"></a> ';
	                }
                }
            },
            {
                title : '操作',
                field : 'id',
                align : 'center',
                formatter : function(value, row, index) {
	                var e = '<a class="btn btn-primary btn-sm ' + s_edit_h + '" href="#" mce_href="#" title="编辑" onclick="edit(\'' + row.jobId + '\',\'' + row.status
	                        + '\')"><i class="fa fa-edit"></i></a> ';
	                var d = '<a class="btn btn-warning btn-sm ' + s_remove_h + '" href="#" title="删除"  mce_href="#" onclick="remove(\'' + row.jobId + '\',\'' + row.status
	                        + '\')"><i class="fa fa-remove"></i></a> ';
	                return e + d;
                }
            }]
		};
		YiMo.BSTable.load(options);
	}

	function pause(id) {
		layer.confirm("确认要停止任务吗?", {
			btn : [ '确定', '取消' ]
		}, function(index) {
			layer.close(index);
			YiMo.ajaxPost({
			    url : prefix + "/pause",
			    data : {
				    'jobId' : id,
			    },
			    refresh : true,
			});
		})
	}

	function resume(id) {
		layer.confirm("确认要恢复任务吗？", {
			btn : [ '确定', '取消' ]
		}, function(index) {
			layer.close(index);
			YiMo.ajaxPost({
			    url : prefix + "/resume",
			    data : {
				    'jobId' : id,
			    },
			    refresh : true,
			});
		})
	}

	function runCheck(status) {
		if (status == '1') {
			layer.msg('运行中的任务不允许操作，请先暂停任务', {
				time : 2000
			// 2s后自动关闭
			});
			return true;
		}
	}

	// 新增
	function add() {
		YiMo.add({
		    url : prefix + '/add' 
		});
	}
	// 编辑
	function edit(id) {
		YiMo.edit({
		    url : prefix + '/edit/' + id 
		});
	}
	//删除
	function remove(id) {
		YiMo.remove({
		    url : prefix + "/remove/"+id,
		});
	}
	//批量删除
	function batchRemove() {
		YiMo.batchRemove({
		    primaryKey : '{job_id}',
		    url : prefix + "/batchRemove",
		});
	}
</script>
</body>
</html>